home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / hwgrcsp4.lha / rcsfreeze.c,v < prev    next >
Text File  |  1993-06-13  |  17KB  |  637 lines

  1. head    1.4;
  2. access;
  3. symbols
  4.     HWGRCSp4:1.4;
  5. locks; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.4
  10. date    93.06.13.15.31.55;    author heinz;    state Exp;
  11. branches;
  12. next    1.3;
  13.  
  14. 1.3
  15. date    93.06.13.15.28.21;    author heinz;    state Exp;
  16. branches;
  17. next    1.2;
  18.  
  19. 1.2
  20. date    93.06.13.14.41.53;    author heinz;    state Exp;
  21. branches;
  22. next    1.1;
  23.  
  24. 1.1
  25. date    93.06.13.14.15.15;    author heinz;    state Exp;
  26. branches;
  27. next    ;
  28.  
  29.  
  30. desc
  31. @This is an AmigaOS SAS/C version of the rcsfreeze scripts.
  32. @
  33.  
  34.  
  35. 1.4
  36. log
  37. @An extra \n to make the log file compatible.
  38. @
  39. text
  40. @/*------------------------------------------------------------------------*/
  41. /*                                                                        *
  42.  *  $Id: rcsfreeze.c,v 1.3 1993/06/13 15:28:21 heinz Exp heinz $
  43.  *
  44.  *  $Log: rcsfreeze.c,v $
  45.  * Revision 1.3  1993/06/13  15:28:21  heinz
  46.  * Now makes the file list first and then does the freeze.
  47.  * The MatchXXX routines barf on me if I try to do it "on the fly"
  48.  *
  49.  * Revision 1.2  1993/06/13  14:41:53  heinz
  50.  * Argh! I forgot to remove the trailing \n in the RCS_link.
  51.  *
  52.  * Revision 1.1  1993/06/13  14:15:15  heinz
  53.  * Initial revision
  54.  *
  55.  *                                                                        */
  56. /*------------------------------------------------------------------------*/
  57.  
  58. /*------------------------------------------------------------------------*/
  59. /*
  60.     This is a SAS/C 6.x replacement for my AmigaOS shell script rcsfreeze.
  61.  
  62.     It should work a lot better for branches. Hopefully it won't freeze the
  63.     branch number anymore, but the highest revision number on that branch
  64.     as it should have done in the first place.
  65.  
  66.     It is a hack and duplicates the shell script functionality just about
  67.     1:1. I needed it in C to make parsing of the revision number
  68.     possible! This program uses the fact that "rlog -b" gives us the
  69.     revision entry we want. To be sure that we don't read a fake revision
  70.     line in the file description that just happens to be suitable, we check
  71.     for the "----[...]" line first, that comes before every revision entry.
  72.  
  73.     There is one thing though, that is pretty nasty. We need to make a list
  74.     of all the filenames first, because if we process the files while
  75.     reading through the directory, the MatchXX() routines will loose track
  76.     of the current position.
  77.  
  78.     No startup code!
  79.  
  80.     sc $* nostkchk optimize link nostartup strmerge
  81.  
  82.  
  83. */
  84.  
  85. /*------------------------------------------------------------------------*/
  86. #ifndef USE_BUILTIN_MATH
  87. #define USE_BUILTIN_MATH
  88. #endif
  89.  
  90. #ifndef __USE_SYSBASE
  91. #define __USE_SYSBASE
  92. #endif
  93.  
  94. /*------------------------------------------------------------------------*/
  95. #include <string.h>
  96. #include <stdlib.h>
  97. #include <dos.h>
  98.  
  99. #define BUFSIZ  256
  100.  
  101. #include <exec/types.h>
  102. #include <exec/memory.h>
  103. #include <dos/dos.h>
  104. #include <dos/dostags.h>
  105. #include <proto/dos.h>
  106. #include <proto/exec.h>
  107.  
  108. /*------------------------------------------------------------------------*/
  109. #define VERSIONFILE ".rcsfreeze.ver"
  110. #define LOGFILE     ".rcsfreeze.log"
  111.  
  112. struct FileList
  113. {
  114.     struct FileList *Next;
  115.     UBYTE           Name[0];
  116.     /* Here follows the name! */
  117. };
  118.  
  119. /*------------------------------------------------------------------------*/
  120. static void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...);
  121. static LONG freeze_revs(struct Library *SysBase,
  122.                         struct Library *DOSBase,
  123.                         STRPTR symrevname);
  124.  
  125. /*------------------------------------------------------------------------*/
  126. int main(int argc, char **argv)
  127. {
  128.     struct Library *SysBase = *((struct Library **)4);
  129.     struct Library *DOSBase = OpenLibrary("dos.library", 37);
  130.  
  131.     if(DOSBase)
  132.     {
  133.         BPTR olddir = CurrentDir(NULL);
  134.         BPTR rcsdir, fh;
  135.         UBYTE buf[BUFSIZ], symrevbuf[BUFSIZ];
  136.         STRPTR symrev = NULL, symrevname;
  137.         LONG versionnumber;
  138.         struct RDArgs *rd;
  139.         UBYTE datebuf[3][20];
  140.         LONG error = 0;
  141.  
  142.         /* Just to get the version string into the code segment ... */
  143.         strcpy(buf, "$VER: rcsfreeze 1.0 (13.6.93) For Joan");
  144.  
  145.         /* First we duplicate the currentdir. So we can restore it later */
  146.         CurrentDir(DupLock(olddir));
  147.  
  148.         if(rd = ReadArgs("SYMREV", (LONG *)&symrev, NULL))
  149.         {
  150.             /* Do we have an RCS_link around? */
  151.             fh = Open("RCS_link", MODE_OLDFILE);
  152.             if(fh)
  153.             {
  154.                 LONG len;
  155.  
  156.                 /* What's in the link? */
  157.                 if(!FGets(fh, buf, BUFSIZ - 1))
  158.                 {
  159.                     buf[0] = 0;
  160.                 } /* if */
  161.  
  162.                 len = strlen(buf);
  163.                 if(len && buf[len - 1] == '\n')
  164.                 {
  165.                     buf[--len] = 0;
  166.                 } /* if */
  167.  
  168.                 Close(fh);
  169.             }
  170.             else
  171.             {
  172.                 strcpy(buf, "RCS");
  173.             } /* if */
  174.  
  175.             if(buf[0])
  176.             {
  177.                 /* Too laze to check for a dirname. We just try it. */
  178.                 rcsdir = Lock(buf, ACCESS_READ);
  179.  
  180.                 if(rcsdir)
  181.                 {
  182.                     UnLock(CurrentDir(rcsdir));
  183.                 } /* if */
  184.             } /* if */
  185.  
  186.             /* Create the version and revision files if necessary */
  187.             fh = Open(VERSIONFILE, MODE_OLDFILE);
  188.             if(!fh)
  189.             {
  190.                 fh = Open(VERSIONFILE, MODE_NEWFILE);
  191.                 if(fh)
  192.                 {
  193.                     FPuts(fh, "0\n");
  194.                     Close(fh);
  195.                 } /* if */
  196.  
  197.                 fh = Open(LOGFILE, MODE_NEWFILE);
  198.                 if(fh)
  199.                 {
  200.                     Close(fh);
  201.                 } /* if */
  202.  
  203.                 fh = Open(VERSIONFILE, MODE_OLDFILE);
  204.             } /* if */
  205.  
  206.             /* Lets advance the version number! */
  207.             versionnumber = 1;
  208.             if(fh)
  209.             {
  210.                 if(!FGets(fh, buf, BUFSIZ - 1))
  211.                 {
  212.                     buf[0] = 0;
  213.                 } /* if */
  214.  
  215.                 StrToLong(buf, &versionnumber);
  216.                 versionnumber++;
  217.  
  218.                 Close(fh);
  219.  
  220.                 fh = Open(VERSIONFILE, MODE_NEWFILE);
  221.                 if(fh)
  222.                 {
  223.                     FPrintf(fh, "%ld\n", versionnumber);
  224.  
  225.                     Close(fh);
  226.                 }
  227.                 else
  228.                 {
  229.                     error = IoErr();
  230.                 } /* if */
  231.             }
  232.             else
  233.             {
  234.                 error = IoErr();
  235.             } /* if */
  236.  
  237.             if(!error)
  238.             {
  239.                 SPrintf(SysBase, symrevbuf, "C_%ld", versionnumber);
  240.                 symrevname = (symrev) ? symrev : symrevbuf;
  241.  
  242.                 Printf("rcsfreeze: symbolic revision number computed: '%s'\n", symrevbuf);
  243.                 Printf("           symbolic revision number used:     '%s'\n", symrevname);
  244.                 PutStr("\n  The two differ only when rcsfreeze was invoked with an argument.\n\n");
  245.                 PutStr("Give a log message, summarizing changes (end with EOF, CTRL-\, or single '.')\n");
  246.  
  247.                 /* We need the date for the freeze */
  248.                 {
  249.                     struct DateTime dt;
  250.  
  251.                     DateStamp(&dt.dat_Stamp);
  252.                     dt.dat_Format  = FORMAT_DOS; /* Compatibility to the old script */
  253.                     dt.dat_Flags   = 0;
  254.                     dt.dat_StrDay  = datebuf[0];
  255.                     dt.dat_StrDate = datebuf[1];
  256.                     dt.dat_StrTime = datebuf[2];
  257.  
  258.                     DateToStr(&dt);
  259.                 }
  260.  
  261.                 /* Let us append the revision freeze text */
  262.                 fh = Open(LOGFILE, MODE_OLDFILE);
  263.                 if(fh)
  264.                 {
  265.                     Seek(fh, 0, OFFSET_END);
  266.  
  267.                     FPrintf(fh, "\nVersion: %s(%s), Date: %s %s %s\n\n",
  268.                             symrevname, symrevbuf,
  269.                             datebuf[0],
  270.                             datebuf[1],
  271.                             datebuf[2]);
  272.  
  273.                     while(FGets(Input(), buf, BUFSIZ - 1))
  274.                     {
  275.                         if(buf[0] == '.' && (!buf[1] || buf[1] == '\n'))
  276.                         {
  277.                             break;
  278.                         } /* if */
  279.  
  280.                         FPuts(fh, buf);
  281.                     } /* while */
  282.  
  283.                     Close(fh);
  284.                 }
  285.                 else
  286.                 {
  287.                     error = IoErr();
  288.                 } /* if */
  289.  
  290.                 if(!error)
  291.                 {
  292.                     error = freeze_revs(SysBase, DOSBase, symrevname);
  293.                 } /* if */
  294.             } /* if */
  295.  
  296.             FreeArgs(rd);
  297.         }
  298.         else
  299.         {
  300.             error = IoErr();
  301.         } /* if */
  302.  
  303.         UnLock(CurrentDir(olddir));
  304.  
  305.         if(error)
  306.         {
  307.             PrintFault(error, NULL);
  308.         } /* if */
  309.  
  310.         CloseLibrary(DOSBase);
  311.     } /* if */
  312.  
  313.     return(0);
  314.  
  315.  
  316. } /* main */
  317.  
  318. /*------------------------------------------------------------------------*/
  319. static void SPutC(void)
  320. {
  321.     __emit(0x16c0);     /* MOVE.B d0,(a3)+ */
  322.  
  323. } /* SPutC */
  324.  
  325. /*------------------------------------------------------------------------*/
  326. static void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...)
  327. {
  328.     RawDoFmt(format, (APTR) ((&format)+1), SPutC, buf);
  329.  
  330. } /* SPrintf */
  331.  
  332. /*------------------------------------------------------------------------*/
  333. static STRPTR mktemp(struct Library *SysBase, struct Library *DOSBase, STRPTR template)
  334. {
  335.     STRPTR cp;
  336.     ULONG val;
  337.     BPTR lock;
  338.  
  339.     cp = template;
  340.     cp += strlen(cp);
  341.     for (val = (ULONG) FindTask(NULL) ; ; )
  342.     {
  343.         if (*--cp == 'X')
  344.         {
  345.             *cp = (val & 0x0f) + '0';
  346.             if(*cp > '9')
  347.             {
  348.                 *cp += 7;
  349.             } /* if */
  350.             val >>= 4;
  351.         }
  352.         else if (*cp != '.')
  353.         {
  354.             break;
  355.         } /* if */
  356.     } /* for */
  357.  
  358.     if (*++cp != 0)
  359.     {
  360.         *cp = 'A';
  361.         while (lock = Lock(template, ACCESS_READ))
  362.         {
  363.             UnLock(lock);
  364.  
  365.             if (*cp == 'Z')
  366.             {
  367.                 *template = 0;
  368.                 break;
  369.             } /* if */
  370.             ++*cp;
  371.         } /* while */
  372.     }
  373.     else
  374.     {
  375.         if (lock = Lock(template, ACCESS_READ))
  376.         {
  377.             UnLock(lock);
  378.             *template = 0;
  379.         } /* if */
  380.     } /* if */
  381.  
  382.     return template;
  383.  
  384. } /* mktemp */
  385.  
  386. /*------------------------------------------------------------------------*/
  387. static struct FileList *GetFileList(struct Library *SysBase,
  388.                                     struct Library *DOSBase,
  389.                                     LONG *errorp)
  390. {
  391.     struct AnchorPath __aligned ap;
  392.     LONG error;
  393.     struct FileList *head = NULL;
  394.  
  395.     memset(&ap, 0, sizeof(ap));
  396.  
  397.     ap.ap_BreakBits = SIGBREAKF_CTRL_C;
  398.  
  399.     error = MatchFirst("#?,v", &ap);
  400.     if(!error)
  401.     {
  402.         for(; !error; error = MatchNext(&ap))
  403.         {
  404.             LONG len = strlen(ap.ap_Info.fib_FileName);
  405.             struct FileList *fl = AllocVec(sizeof(*fl) + len + 1, MEMF_ANY);
  406.  
  407.             if(fl)
  408.             {
  409.                 fl->Next = head;
  410.                 strcpy(fl->Name, ap.ap_Info.fib_FileName);
  411.  
  412.                 head = fl;
  413.             }
  414.             else
  415.             {
  416.                 error = ERROR_NO_FREE_STORE;
  417.                 break;
  418.             } /* if */
  419.         } /* for */
  420.         MatchEnd(&ap);
  421.     } /* if */
  422.  
  423.     if(error == ERROR_NO_MORE_ENTRIES)
  424.     {
  425.         error = 0;
  426.     } /* if */
  427.  
  428.     *errorp = error;
  429.  
  430.     return(head);
  431.  
  432. } /* GetFileList */
  433.  
  434. /*------------------------------------------------------------------------*/
  435. static void FreeFileList(struct Library *SysBase, struct FileList *fl)
  436. {
  437.     struct FileList *flnext;
  438.  
  439.     for(; fl; fl = flnext)
  440.     {
  441.         flnext = fl->Next;
  442.  
  443.         FreeVec(fl);
  444.     } /* for */
  445.  
  446. } /* FreeFileList */
  447.  
  448. /*------------------------------------------------------------------------*/
  449. static LONG freeze_revs(struct Library *SysBase,
  450.                         struct Library *DOSBase,
  451.                         STRPTR symrevname)
  452. {
  453.     LONG error;
  454.     UBYTE buf[BUFSIZ];
  455.     struct FileList *head, *fl;
  456.  
  457.     head = GetFileList(SysBase, DOSBase, &error);
  458.  
  459.     if(!error)
  460.     {
  461.         for(fl = head; !error && fl; fl = fl->Next)
  462.         {
  463.             BPTR fh;
  464.             char tmpbuf[20],cmdbuf[BUFSIZ];
  465.  
  466.             strcpy(tmpbuf, "PIPE:rfXXX.XXX");
  467.             if(mktemp(SysBase, DOSBase, tmpbuf))
  468.             {
  469.                 SPrintf(SysBase, cmdbuf, "rlog >%s -b \"%s\"\n",
  470.                         tmpbuf, fl->Name);
  471.  
  472.                 if(!(error = SystemTags(cmdbuf,
  473.                                         SYS_UserShell, TRUE,
  474.                                         TAG_END)))
  475.                 {
  476.                     fh = Open(tmpbuf, MODE_OLDFILE);
  477.                     if(fh)
  478.                     {
  479.                         while(FGets(fh, buf, BUFSIZ - 1) && !error)
  480.                         {
  481.                             if(strlen(buf) > 10 && !memcmp(buf, "----------", 10))
  482.                             {
  483.                                 if(FGets(fh, buf, BUFSIZ - 1))
  484.                                 {
  485.                                     if(strlen(buf) > 10 &&
  486.                                        !memcmp(buf, "revision ", 9))
  487.                                     {
  488.                                         /* This is the version number we are
  489.                                            looking for!! */
  490.                                         STRPTR version = &buf[9];
  491.                                         ULONG len = strlen(version);
  492.  
  493.                                         if(version[len - 1] == '\n')
  494.                                         {
  495.                                             version[--len] = 0;
  496.  
  497.                                         } /* if */
  498.  
  499.                                         if(len > 2)
  500.                                         {
  501.                                             Printf("rcsfreeze: '%s' %s\n",
  502.                                                    version, fl->Name);
  503.  
  504.                                             SPrintf(SysBase, cmdbuf, "rcs -q \"-n%s:%s\" \"%s\"\n",
  505.                                                     symrevname,
  506.                                                     version,
  507.                                                     fl->Name);
  508.                                             error = SystemTags(cmdbuf,
  509.                                                                SYS_UserShell, TRUE,
  510.                                                                TAG_END);
  511.                                         } /* if */
  512.                                         break;
  513.                                     } /* if */
  514.                                 } /* if */
  515.                             } /* if */
  516.                         } /* while */
  517.  
  518.                         Close(fh);
  519.                     }
  520.                     else
  521.                     {
  522.                         error = ERROR_OBJECT_NOT_FOUND;
  523.                     } /* if */
  524.                 } /* if */
  525.             }
  526.             else
  527.             {
  528.                 error = ERROR_BAD_TEMPLATE;
  529.             } /* if */
  530.  
  531.             if(error)
  532.             {
  533.                 break;
  534.             } /* if */
  535.         } /* for */
  536.     } /* if */
  537.  
  538.     FreeFileList(SysBase, head);
  539.  
  540.     return(error);
  541.  
  542. } /* freeze_revs */
  543.  
  544. /*------------------------------------------------------------------------*/
  545.  
  546. /* Ende des Quelltextes */
  547.  
  548. @
  549.  
  550.  
  551. 1.3
  552. log
  553. @Now makes the file list first and then does the freeze.
  554. The MatchXXX routines barf on me if I try to do it "on the fly"
  555. @
  556. text
  557. @d3 1
  558. a3 1
  559.  *  $Id: rcsfreeze.c,v 1.2 1993/06/13 14:41:53 heinz Exp heinz $
  560. d6 4
  561. d228 1
  562. a228 1
  563.                     FPrintf(fh, "\nVersion: %s(%s), Date: %s %s %s\n",
  564. @
  565.  
  566.  
  567. 1.2
  568. log
  569. @Argh! I forgot to remove the trailing \n in the RCS_link.
  570. @
  571. text
  572. @d3 1
  573. a3 1
  574.  *  $Id: rcsfreeze.c,v 1.1 1993/06/13 14:15:15 heinz Exp heinz $
  575. d6 3
  576. d30 5
  577. d59 1
  578. d69 7
  579. d77 4
  580. a80 4
  581. void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...);
  582. LONG freeze_revs(struct Library *SysBase,
  583.                  struct Library *DOSBase,
  584.                  STRPTR symrevname);
  585. d283 1
  586. a283 1
  587. void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...)
  588. d290 1
  589. a290 1
  590. STRPTR mktemp(struct Library *SysBase, struct Library *DOSBase, STRPTR template)
  591. d344 3
  592. a346 3
  593. LONG freeze_revs(struct Library *SysBase,
  594.                  struct Library *DOSBase,
  595.                  STRPTR symrevname)
  596. d350 1
  597. a350 1
  598.     UBYTE buf[BUFSIZ];
  599. d361 59
  600. d427 1
  601. a427 1
  602.                         tmpbuf, ap.ap_Info.fib_FileName);
  603. d459 1
  604. a459 1
  605.                                                    version, ap.ap_Info.fib_FileName);
  606. d464 1
  607. a464 1
  608.                                                     ap.ap_Info.fib_FileName);
  609. a492 2
  610.  
  611.         MatchEnd(&ap);
  612. d495 1
  613. a495 4
  614.     if(error == ERROR_NO_MORE_ENTRIES)
  615.     {
  616.         error = 0;
  617.     } /* if */
  618. @
  619.  
  620.  
  621. 1.1
  622. log
  623. @Initial revision
  624. @
  625. text
  626. @d3 1
  627. a3 1
  628.  *  $Id: rcsfreeze.c,v 1.1 1993/06/13 13:52:23 heinz Exp $
  629. d6 1
  630. a6 1
  631.  * Revision 1.1  1993/06/13  13:52:23  heinz
  632. a8 1
  633.  *
  634. d95 1
  635. d101 6
  636. @
  637.